<template>
	<div class="Item">
		<el-dialog title="创建考试库" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">

			<el-input v-model="questionBankName" placeholder="试卷库名称"></el-input>
			<el-input v-model="questionBankDescribe" placeholder="试卷库描述" style="margin-top: 0.625rem;"></el-input>
			<span slot="footer" class="dialog-footer">
				<el-button @click="dialogVisible = false">取 消</el-button>
				<el-button type="primary" @click="creatQuestion()" class="Item_button">确 定</el-button>
			</span>
		</el-dialog>

		<el-button class="Item_button" @click="dialogVisible=true">创建试卷库</el-button>
		<el-table :data="MyAllQuestionBank" border style="width: 90%;margin-top: 1.25rem;">
			<el-table-column prop="questionBankName" label="题库名称" width="180">
			</el-table-column>
			<el-table-column prop="questionBankDescribe" label="题库描述" width="180">
			</el-table-column>
			<el-table-column prop="createTime" label="创建时间">
			</el-table-column>
			<el-table-column prop="" label="操作">
				<template slot-scope="scope">
					<el-button type="success" icon="el-icon-search" circle @click="Serchtest(scope.row.id)"></el-button>
					<el-button type="primary" icon="el-icon-edit" circle @click="handledit(scope.$index, scope.row)"></el-button>
					<el-button type="danger" icon="el-icon-delete" circle @click="deleteBank(scope.row.id)"></el-button>
				</template>
			</el-table-column>
		</el-table>

	</div>
</template>

<script>
	import {
		HttpManager
	} from "../../../../request/Teacher.js"
	export default {
		data() {
			return {
				questionBankDescribe: '题库描述',
				questionBankName: '题库名称',
				dialogVisible: false,
				MyAllQuestionBank: [],
				tableData: [{
					date: '2016-05-02',
					name: '王小虎',
					address: '上海市普陀区金沙江路 1518 弄'
				}, {
					date: '2016-05-04',
					name: '王小虎',
					address: '上海市普陀区金沙江路 1517 弄'
				}, {
					date: '2016-05-01',
					name: '王小虎',
					address: '上海市普陀区金沙江路 1519 弄'
				}, {
					date: '2016-05-03',
					name: '王小虎',
					address: '上海市普陀区金沙江路 1516 弄'
				}]
			}
		},
		methods: {
			//给题库添加试卷
			addTestPaperToBank() {
				var parmas = {
					questionBankId: '', //题库id
					testPaperId: '', //试卷id
				}
				HttpManager.addTestPaperToBank(this.qs.stringify(params)).then(e => {
					console.log(e);
				})
			},
			//创建试题库
			creatQuestion() {
				var params = {
					questionBankDescribe: this.questionBankDescribe, //试题库描述
					questionBankName: this.questionBankName, //试题库名
				}
				HttpManager.creatQuestion(params).then(e => {
					console.log(e);
					this.dialogVisible = false;
					this.getMyAllQuestionBank();
				})
			},
			//删除试题库
			deleteBank(id) {
				var parmas = {
					questionBankId:id //题库id
				}
				HttpManager.deleteBank(this.qs.stringify(parmas)).then(e => {
					console.log(e);
					this.$message({
						message: '删除成功',
						type: 'success'
					});
					this.getMyAllQuestionBank();
				})
			},
			//删除题库中试卷
			deleteTestPaperFromBank() {
				var parmas = {
					questionBankId: '', //题库id
					testPaperId: '', //	试卷id
				}
				HttpManager.deleteTestPaperFromBank(this.qs.stringify(params)).then(e => {
					console.log(e);
				})
			},
			//获取自己所有的试题库
			getMyAllQuestionBank() {

				HttpManager.getMyAllQuestionBank().then(e => {
					console.log(e);
					this.MyAllQuestionBank = e.data.data;
				})
			},
			
			handleClose() {
				this.dialogVisible = false;
			},
			Serchtest(id)
			{
				this.$router.push({path:'/paperManagement',query:{id:id}});
			}
		},
		created() {
			this.getMyAllQuestionBank();
		}
	}
</script>

<style scoped="scoped">
	.Item {
		margin-left: 5%;
	}

	.Item_button {
		margin-top: 1.25rem;
		background-color: #03D3BD;
		border: none;
		color: white;
	}
</style>
